package TUILayer;//makes this class a part of the TUILayer package
import java.util.Scanner;
import ControlLayer.*;//The TUILayer needs to know the ControlLayer
/**
 * 
 * User interface - main menu
 * The entry-point for the application:
 * Create an instance of class MainMenuUI and the constructor starts the application
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 *                    
 * (KBH): 2008.10.24: Change af manimenuStart to if
 */
public class MainMenuUI
{
    private ProductUI proUI;//references to other UI objects
    private SupplierUI supUI;
      
    public MainMenuUI()
    {
       
    }
    
    public void start()
    {
        mainMenuStart();
    }
   
    public void mainMenuStart()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise = writeMainMenu();
            if(choise == 1)
            {
                startProductUI(); // Starts the AddressBook class
            }
            else
            {
                if(choise == 2)
                { 
                    startSupplierUI(); // Starts the DVDUI class
                }
                else
                {
                    writeEnd();
                    exit = true;
                }//end else
            }//end else
        }//end while
    }//end start
    
    private int writeMainMenu()
    {       
            // creates a keyboard object to read input
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** MainMenu ***");
            System.out.println(" (1) Products");
            System.out.println(" (2) Suppliers");
            System.out.println(" (3) Close");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    
    private void startProductUI()
    {
        // Turns work over to the ProductUI
        proUI= new ProductUI();
        proUI.start();     
    }

    private void startSupplierUI()
    {
        // Turns work over to the SupplierUI
        supUI = new SupplierUI();
        supUI.start();
    }
    
    
    private void writeEnd()
    {
        System.out.println(" The System is shuting down ");
    }
}
